﻿using Microsoft.AspNetCore.Mvc;
using Vending_machine_system.LogicalLayer;
using Vending_machine_system.VendingMachineClass;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace Vending_machine_system.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class UserController : ControllerBase
    {

        private readonly UserLayer db;
        public UserController(UserLayer db)
        {
            this.db = db;
        }
        /// <summary>
        /// 根据用户状态，用户手机号，所属职责，用户姓名等查询分页显示
        /// </summary>
        /// <param name="IsDeleted"></param>
        /// <param name="Userphone"></param>
        /// <param name="UserdutiesId"></param>
        /// <param name="Pageindex"></param>
        /// <param name="Pagesize"></param>
        /// <param name="UserName"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetUsers(int Pageindex, int Pagesize, bool IsDeleted, long Userphone = 0, long UserdutiesId = 0, string UserName = "")
        {
            var list = db.GetUsers(out int Tolcount,Pageindex,Pagesize,IsDeleted,Userphone,UserdutiesId,UserName);
            Tolcount=list.Count();
            return Ok(new
            {
                Tolcount,
                list
           });
        }
        /// <summary>
        /// 用户注册
        /// </summary>
        /// <param name="userInfo"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult Post(UserInfoClass userInfo)
        {
            return Ok(db.AddUser(userInfo));
        }
        /// <summary>
        /// 删除用户信息
        /// </summary>
        /// <param name="UserId"></param>
        /// <returns></returns>
        [HttpDelete]
        public IActionResult Deletion(long UserId)
        {
            return Ok(db.Deletion(UserId));
        }
        /// <summary>
        /// 用户查询反填数据
        /// </summary>
        /// <param name="userInfo"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetUpdate(long UserId)
        {
            return Ok(db.GetUpdate(UserId));
        }
        //用户状态修改
        [HttpPost]
        public IActionResult Pseudodeletion(long UserId, bool IsDeleted)
        {
               return Ok(db.Pseudodeletion(UserId, IsDeleted));      
        }
        //用户信息修改
        [HttpPut]
        public IActionResult UpdateUser(UserInfoClass userInfo)
        {
            return Ok(db.UpdateUser(userInfo));
        }
    }
}
